package com.wufeng.springcloud.controller;

import com.wufeng.springcloud.entities.CommonResult;
import com.wufeng.springcloud.entities.Payment;
import com.wufeng.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/payment")
public class PaymentController {

    @Value("${server.port}")
    private String port;
    @Resource
    private PaymentService paymentService;

    @PostMapping(value = "/create")
    public CommonResult add(@RequestBody Payment payMent) {
        return paymentService.create(payMent);
    }

    @GetMapping(value = "/list/{id}")
    public CommonResult list(@PathVariable("id") Long id) {
        return paymentService.findById(id);
    }

    @GetMapping(value = "list")
    public CommonResult listAll() {
        return paymentService.findAll();
    }

    @PutMapping(value = "/update")
    public CommonResult update(@RequestBody Payment payment) {
        return paymentService.update(payment);
    }

    @DeleteMapping(value = "/delete/{id}")
    public CommonResult update(@PathVariable Long id) {
//        System.out.println("");
        return paymentService.delete(id);
    }

    @GetMapping(value = "/lb")
    public String lb() {
        return port;
    }

}
